
/**
 * Created by LiuDan on 2017/07/22.
 * 公共.js
 */
//tools
var tools={
    //设置cookie
    setCookie:function(name,value,days){
        var exp=new Date();
        exp.setTime(exp.getTime() + days*24*60*60*1000);
        var arr=document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
        document.cookie=name+"="+escape(value)+";expires="+exp.toGMTString();
    },
    //读取cookie
    getCookie:function(name) { //读取cookie
        var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
        if (arr != null) return unescape(arr[2]);
        return null;
    },
    //取url里面参数
    getString:function(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return decodeURIComponent(r[2]);
        return null;
    },
    /**
     * 设置页面loading显示或者隐藏
     * @param {boolean} boolShowing 为true时，显示loading，否则隐藏
     */
    setPageLoading:function (boolShowing) {
        var loading='<div class="loadPageImg dn" id="loadPage"><img src="/home/img/loading.svg"/></div>'
        if( $('body').find('.loadPageImg').length==0){
            $('body').append(loading);
        }
        $('#loadPage')[boolShowing ? 'show' : 'hide']();
        return  this;
    },
    /*点击按钮加载ajax状态
     参数说明 : obj:  当前点击对象
     text: 执行中文字说明
     bool: 执行状态  执行中传 true text为执行中的文字状态,执行结束传false text为执行后的状态
     */
    ajaxLoading:function(obj,text,bool){
        obj.html(text)
        if(bool){
            obj.addClass('loginenable')
        }else{
            obj.removeClass('loginenable')
        }
    },
    //弱提示
    comPop: function (text) {
        var str = '<div class="layer layerOut"><p></p></div>'
        if ($('body').find('.layer').length<= 0) {
            $('body').append(str);
        }
        $('.layer').css("display","inline-table");
        $('.layer p').html(text)
        setTimeout(function() {
            $('.layer').remove();
        },4000)
    },
    //弹窗
    alertMask:function(text){
        var str='<div class="alert-layer" id="alert-layer"><div class="alert-box abs-lm"> <div class="auto"><div class="alert-title dark-gray size16 alert-cont"><p></p></div><div class="alert-btn clearfix ta-c"><div class="alert-btn-right dark-blue size36" id="iknow">我知道了</div></div></div></div></div>';
        if ($('body').find('.alert-layer').length>=0) {
            $('body').append(str);
        }
        $('.alert-layer').show();
        $('.alert-cont p').html(text);
        $('#iknow').on('click',function(){
            $('.alert-layer').hide();
        })
    },
    //createDIV
    createDIV: function(clN, htm) {
        var oDiv = document.createElement("div");
        oDiv.className = clN;
        if (htm) {
            oDiv.innerHTML = htm;
        }
        document.body.appendChild(oDiv);
        return oDiv;
    }
}
//表单验证
var registerEvt={
    //手机号正则
    regPhone:function(tel){
        var regPhone=/^1[3-578]\d{9}$/;
        if(regPhone.test(tel)){
            return true;
        }else{
            return false;
        }
    },
    //邮箱正则
    regEmail:function(eml){
        var regEmail=/^\w+([-+.]\w+)*@\w+([-.]\w{2,})*\.\w{2,}([-.]\w{2,})*$/;
        if(regEmail.test(eml)){
            return true;
        }else{
            return false;
        }
    },
    //密码正则 6-18位
    passwordReg:function(pw){
        var reg=/^(?!\s+)[\w\W]{6,18}$/;
        if(reg.test(pw)){
            return true;
        }else{
            return false;
        }
    },
    //为空 undefined null NaN 验证
    regTrue:function(val){
        if(!val||val==""||val=="undefined"||val=="null"){
            return false;
        }else{
            return true;
        }
    }

}
//浏览器判断升级提示
var browserUpgrade = '<div class="browserBody" style="display:none;">' +
    '<div class="bcgop"></div>' +
    '<div class="browserBody-text">' +
    '<p>您目前使用的浏览器可能无法实现最佳浏览效果，建议使用Chrome(谷歌)、Firefox(火狐)、Edge、IE9及IE9以上版本浏览器。</p>' +
    '<a href="/web/html/Download.html">立即升级</a>' +
    '<img src="/home/img/BWcolse.png"/>' +
    '</div>' +
    '</div>';
//浏览器判断
function myBrowser(){
    var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
    var isOpera = userAgent.indexOf("Opera") > -1; //判断是否Opera浏览器
    var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 && !isOpera; //判断是否IE浏览器
    var isFF = userAgent.indexOf("Firefox") > -1; //判断是否Firefox浏览器
    var isSafari = userAgent.indexOf("Safari") > -1; //判断是否Safari浏览器
    var isChrome = userAgent.indexOf("Chrome") > -1; //判断是否谷歌浏览器
    var isQQ = userAgent.indexOf("QQBrowser") > -1 && userAgent.indexOf("Chrome") == -1; //QQ浏览器非极速模式
    if (isIE) {
        var IE5 = IE55 = IE6 = IE7 = IE8 = false;
        var reIE = new RegExp("MSIE (\\d+\\.\\d+);");
        reIE.test(userAgent);
        var fIEVersion = parseFloat(RegExp["$1"]);
        IE55 = fIEVersion == 5.5;
        IE6 = fIEVersion == 6.0;
        IE7 = fIEVersion == 7.0;
        IE8 = fIEVersion == 8.0;
        IE9 = fIEVersion == 9.0;
        if (IE55) {
            return "IE55";
        }
        if (IE6) {
            return "IE6";
        }
        if (IE7) {
            return "IE7";
        }
        if (IE8) {
            return "IE8";
        }
        if (IE9) {
            return "IE9";
        }
    }else if(isQQ){
        return "QQ";
    }

}//myBrowser() end
//==========================================================================================
$("body").append(template.compile(browserUpgrade));


//以下是调用上面的函数
if (myBrowser() == "IE55") {
    window.location.href = "/web/html/Download.html";
}else if (myBrowser() == "IE6") {
    window.location.href = "/web/html/Download.html";
}else if (myBrowser() == "IE7") {
    window.location.href = "/web/html/Download.html";
}else if (myBrowser() == "IE8") {
    window.location.href = "/web/html/Download.html";
}else if(myBrowser() == "IE9"){
    window.location.href = "/web/html/Download.html";
}else if(myBrowser() == "QQ"){
    window.location.href = "/web/html/Download.html";
}